package com.djsearch.adapter;

import com.djsearch.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ShareAdapter extends BaseAdapter {

	View[] itemViews;
	private LayoutInflater mInflater;
	private Context context;
	TextView title;
	ImageView image;

	public ShareAdapter(Context context, String[] shareStrings, int[] shareIcon) {
		// TODO Auto-generated constructor stub
		if (context == null) {
			return;
		}
		this.context = context;
		this.mInflater = LayoutInflater.from(context);
		itemViews = new View[shareStrings.length];
		for (int i = 0; i < itemViews.length; i++) {
			itemViews[i] = makeItemView(shareStrings[i], shareIcon[i]);
		}
	}

	private View makeItemView(String reasons, int marks) {

		View itemView = mInflater.inflate(
				R.layout.share_item, null);
		title = (TextView) itemView
				.findViewById(R.id.text);
		title.setText(reasons);
		image = (ImageView) itemView
				.findViewById(R.id.icon);

		image.setImageResource(marks);
		return itemView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return itemViews.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return itemViews[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			// itemViews[position].setOnClickListener(new OnClickListener() {
			//
			// @Override
			// public void onClick(View v) {
			// // TODO Auto-generated method stub
			// ((CancelOrderActivity)context).setReason(title.getText().toString());
			// image.setVisibility(View.VISIBLE);
			// }
			// });
			return itemViews[position];
		}
		return convertView;
	}
}
